varying vec2 vTexCoord;
uniform sampler2D glow;
const float K = 4.0;
uniform vec2 blurDirection; // (1,0) for horizontal blur, (0,1) for vertical blur
uniform float blurSize;    // the size of the blur
uniform int n;               // number of samples taken

void main(){
    float fn = float(n);
    float s = blurSize / fn;   // blur step
    vec4 c = vec4(0,0,0,0);
    float fi;
    float w = 0.0;
    float sw = 0.0;

    for (int i = -n+1; i<n; i++) {
        fi = float(i);
        vec2 coord = vTexCoord + (fi * s * blurDirection);
        w =  (1.0 - pow(abs(fi)/fn, 0.3));
        c += texture2D(glow, coord) * w;
        sw += w;
    }
    c = c / sw;
    c.a = (pow(c.r, 0.3) + pow(c.g, 0.3) + pow(c.b, 0.3)) / 3.0 * 1.5;
    //c.a = pow((c.r + c.g + c.b) / 3.0, 0.3) * 1.5;
    c.rgb = c.rgb * K;
    gl_FragData[0] = c;
}
